package com.mycomp.cm.model;

import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/*
 * POJO
 * -------
 * 
 */

@Entity
@Table(name = "CM_USERS", schema = "chpc")
public class User implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// Properties

	@Id
	private String userName;
	@Column(nullable = false)
	private String password;
	@Column(nullable = false)
	private String name;

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinTable(name = "USER_CONTACTS", 
	joinColumns = { @JoinColumn(name = "USERNAME") }, 
	inverseJoinColumns = { @JoinColumn(name = "CONTACT_ID") })
	private Set<Contact> userContacts = new TreeSet<Contact>();

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Contact> getUserContacts() {
		return userContacts;
	}

	public void setUserContacts(Set<Contact> userContacts) {
		this.userContacts = userContacts;
	}

}
